from src.python.db.base.orm import Model, IntegerField, StringField


class User(Model):
    __table__ = 'users'

    id = IntegerField(primary_key=True)
    username = StringField()
    nickname = StringField()
    email = StringField()
    phone = StringField()
    password = StringField()

    @classmethod
    def check_by_user_name(cls, username):
        return User.find_all(where=f" username = ? ", args=[username])

    @classmethod
    def verify_account_is_exist(cls, account):
        return User.find_all(where=f" email = ?  or phone = ? ", args=[account, account])

    @classmethod
    def verify_by_account_and_password(cls, account1, account2, password):
        return User.find_all(where=f" ( email = ?  or phone = ? ) and password = ? ", args=[account1, account2, password])


if __name__ == "__main__":
    # 创建实例:
    # user = User(name='sam')
    # 存入数据库:
    # user.insert()
    # 查询所有User对象:
    # users = User.find_all()
    # print(users)
    # num = User.find_number("id")
    # print(num)
    res = User.check_by_user_name("Michael")
    print(res)
